package com.woniuxy.handler;

import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.dsna.util.images.ValidateCode;

@Controller
@RequestMapping("/PicCode")
public class PictureCodeHandler {
    @RequestMapping("/loginCode")
    public void getCode(HttpServletRequest request, HttpServletResponse response) {
        // 创建验证码对象
        ValidateCode code = new ValidateCode(150, 50, 4, 50);
        // 获取验证码值
        String codeVal = code.getCode();
        
        System.out.println("验证码的值：" + codeVal);
        // 将值存到session
        request.getSession().setAttribute("loginCode", codeVal);
        // 将验证码写出
        try {
            code.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
